package in.muton.edushare.poll.panels;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.schedules.widgets.DateLabel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.edushare.common.vo.Poll;

public class SummaryPanel extends EdusharePanel {
	private static final long serialVersionUID = -7203446562684908452L;
	private IModel<Poll> pollModel;

	public SummaryPanel(String id, IModel<Poll> model, EduShareBasePage page) {
		super(id, page);
		setPollModel(model);
		add(new Label("pollName", getPollModel().getObject().getPollName()));
		add(new Label("pollDesc", getPollModel().getObject().getPollDesc()));
		if (getPollModel().getObject().getPollStartDate() != null)
			add(new DateLabel("startDate", getPollModel().getObject()
					.getPollStartDate(), 0));
		else
			add(new Label("startDate", "Not started"));
		add(new DateLabel("endDate", getPollModel().getObject()
				.getPollEndDate(), 0));
		add(new Label("anonymous", new Model<String>() {
			private static final long serialVersionUID = 2023756860782054266L;

			@Override
			public String getObject() {
				if (getPollModel().getObject().getPollAnonymous() == Poll.ANONYMOUS_POLL)
					return "Anonymous poll.";
				else
					return "Not an anonymous poll.";
			}
		}));

		add(new Label("creator", getPollModel().getObject().getCreator()
				.getCompleteUserName()));

		add(new Label("public", new Model<String>() {
			private static final long serialVersionUID = -4320247492054203071L;

			@Override
			public String getObject() {
				if (getPollModel().getObject().getPollResultsPublic() == Poll.POLL_RESULT_OPEN)
					return "Poll results are public";
				else
					return "Poll results are confidential";
			}
		}));
		add(new Label("audience", getPollModel().getObject().getPollAudi(getORMInterface())));
	}

	public void setPollModel(IModel<Poll> pollModel) {
		this.pollModel = pollModel;
	}

	public IModel<Poll> getPollModel() {
		return pollModel;
	}
}
